package com.yxzx.statistics.controller;


import com.yxzx.common.YxzxResult;
import com.yxzx.statistics.service.StatisticsDailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author kongfuzi
 * @since 2020-08-15
 */
@Slf4j
@CrossOrigin
@Api(tags = "统计报表控制器")
@RestController
@RequestMapping("/statistics/statistics-daily")
public class StatisticsDailyController {
    @Autowired
    private StatisticsDailyService statisticsDailyService;

    @ApiOperation("添加日期统计数据")
    @PostMapping("{day}")
    public YxzxResult createStatisticsByDate(@ApiParam(name = "day", value = "统计日期", required = true) @PathVariable String day){
        int result = statisticsDailyService.createStatisticsByDay(day);
        return result > 0 ? YxzxResult.ok() : YxzxResult.error();
    }

    @ApiOperation("分类统计数据")
    @GetMapping("showChart/{type}/{begin}/{end}")
    public YxzxResult showChart(
            @ApiParam(name = "type", value = "统计类型",required = true) @PathVariable  String type,
            @ApiParam(name = "begin",value = "开始日期",required = true) @PathVariable  String begin,
            @ApiParam(name = "end",  value = "结束日期",required = true) @PathVariable  String end
    ){
        Map<String,Object> map = statisticsDailyService.getChartData(type,begin,end);
        return YxzxResult.ok().data(map);
    }

}

